package cn.study.controller;

import cn.study.entity.StudyEmployee;
import cn.study.entity.StudyExamination;
import cn.study.service.StudyEmployeeService;
import cn.study.service.StudyExaminationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.Month;
import java.time.Year;
import java.time.YearMonth;
import java.util.Date;
import java.util.List;

@Slf4j
@Controller
@RequestMapping
@Component
public class ThreadController {
 /*   private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");*/
//    String  a;
//    int b;
    int count=1;
   @Autowired
    private JavaMailSender mailSender;
   @Resource
   StudyEmployeeService studyEmployee;
  @Scheduled(fixedRate = 360000)//每隔一小时执行一次
    public void reportCurrentTime() {
       /* String aaa=dateFormat.format(new Date());*/
        List<String> list=studyEmployee.getemail();
        for(String s:list){
            if(count==1) {
                System.out.println("已发送邮件给该部门所有员工！");
                SimpleMailMessage message = new SimpleMailMessage();
                message.setFrom("2969933953@qq.com");
                message.setTo(s);
                message.setSubject("主题：考试提醒");
                message.setText("你还有6个小时考试，请注意时间！");
                mailSender.send(message);
                count++;
            }
        }
//        System.out.println("现在时间：" + aaa);
//        System.out.println("---------------------"+a+"-----------------");

        }

    }
